<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>谈心谈话</title>
		
		<link href="../bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" href="../layui/css/layui.css" media="all" />
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}
			.class_div_scorelist{
				width:100%;
				height:100vh;
			}
			.class_div_header{
				height:15vh;
				background-image:url(../img/header.png);
				background-repeat:no-repeat;
				background-size:100%;
			}
			.class_h1_header_title{
				margin:0;
				text-align: center;
				color:#FFFFFF;
				line-height: 7vh;
			}
			.class_div_title {
				font-weight: bold;
				font-size: 1.3em;
			}
			.class_div_table{
				margin-top:20px;
			}
			.class_div_btn_sub{
				float: right;
			}
			
			.class_div_logout{
				position: fixed;
				bottom:50px;
				right: 50px;
			}
			.class_div_logout button{
				width: 80px;
				height:40px;
			}
			#lilunTable{
				width: 100%;
			}
		</style>
	</head>
	<body>
		<div class="class_div_scorelist">
			<div class="class_div_header">
			</div>
			<div class="row class_div_container" style="margin:0px">
				<div class="col-xs-10 col-xs-offset-1">
					<div class="class_div_table">
						<div class="container">
							<span class="class_div_title">
								谈心谈话阶段
							</span>
							<span class="class_div_btn_sub">
								<button type="button" class="btn btn-danger" onclick="exportExcel('currt')">导出当前阶段列表</button>
								<button type="button" class="btn btn-danger" onclick="exportExcel('all')">导出全部阶段列表</button>
							</span>
							<table id="lilunTable" lay-filter="test"></table>
						</div>
					</div>
				</div>
			</div>
			<div class="class_div_logout">
				<a href="Router.html"><button type="button" class="btn btn-info">返回首页</button></a>
			</div>
		</div>
		<script src="../js/jquery-1.12.4/jquery.min.js"></script>
		<script src="../bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
		<script src="../js/jquery-2.1.4/jquery.min.js"></script>
		<script type="text/javascript" src="../layui/layui.js"></script>
		
		<script type="text/javascript" src="../js/common.js" ></script>
		
		<script type="text/javascript" src="../js/ip.js" ></script>
		<script type="text/javascript">
			var stageId = 2;
			var sort = 0;
			var scoreInfoId = 1;
			var refreshid = 0;
			var time;
			
			var dataList = [];
			
			$(document).ready(function() {
				getTableHeader()
				//time = setInterval("getTableHeader()",5000);	
			});

			//获取表头评分人列表
			function getTableHeader() {
				var postaddress = ip + '/admin/grade/get';
				var info = new Object();
				info.stageId = 2;
				info.refreshid = refreshid;
				$.ajax({
					//几个参数需要注意一下
					type: "POST", //方法类型
					dataType: "json", //预期服务器返回的数据类型
					contentType: "application/json;charset=utf-8",
					url: postaddress, //url
					data: JSON.stringify(info),
					success: function(result) {
						refreshid++;
						if(result.data){
							let headerList = handelRaterData(result.data);
							let candidateList = handelCandidateData(result.data);
							creatTable(candidateList, headerList);
						}
					},
					error: function() {
						alert("错误");
						window.clearInterval(time);  
					}
				});
			}

			function creatTable(tableData, headerList) {
				let index = {
					title: '',
					field: 'name'
				}
				let scoreField = [{
					title:'最高分',
					field:'maxScore',
					sort:true,
					align:'center'
				},{
					title:'最低分',
					field:'minScore',
					sort:true,
					align:'center'
				},{
					title:'平均分',
					field:'average',
					sort:true,
					align:'center'
				}]
				headerList.unshift(index);
				headerList = headerList.concat(scoreField);
				layui.use('table', function() {
					let table = layui.table;
					table.render({
						elem: '#lilunTable',
						size: 'xs',
						data: tableData,
						limit:100,
						cols: [headerList],
					});
				});
			}
			
			function handelRaterData(list) {
				let raterList = [];
				let reuturnRaterList = [];
				raterList = list[0].raterGraded;
				for(let i = 0; i < raterList.length; i++) {
					let info = new Object();
					info.title = raterList[i].raterName;
					info.field = raterList[i].raterId;
					info.align = 'center';
					info.templet = function(d){
						let data = d[raterList[i].raterId];
						let verify = d['verify' + raterList[i].raterId];
						if(verify === 0){
							return "<p style='text-align:center;'>同校</p>"
						}else if(verify === 1){
							return "<p style='text-align:center;background:#F0E68C'>"+ data +"</p>";
						}else if(verify === 2){
							return "<p style='text-align:center;background:#98FB98'>"+ data +"</p>";
						}else if(verify === 3){
							return "<p style='text-align:center;background:#FF9090'>" + data + "</p>";
						}
					}
					reuturnRaterList[i] = info;
				}
				return reuturnRaterList;
			}
			
			function handelCandidateData(list) {
				let candidateList = [];
				let returnList = [];  
				for(let i = 0; i < list.length; i++) {
					let info = new Object();
					info.name = list[i].name;
					info.maxScore = list[i].maxScore;
					info.minScore = list[i].minScore;
					info.average = list[i].average;
					let raterData = list[i].raterGraded;
					for(let j = 0; j < raterData.length; j++) {
							info[raterData[j].raterId] = raterData[j].fraction;
							info['verify' + raterData[j].raterId] =raterData[j].verify;
					}
					returnList[i] = info;
				} 
				return returnList;
			}

			function exportExcel() {
				location.href = ip + '/admin/grade/one_excel?stageId=2'
			}
		</script>
	</body>
</html>
